const express = require('express');
const router = express.Router();
const { pool } = require('../config/database');

// 获取最新上架图书
router.get('/', async (req, res) => {
    try {
        const [books] = await pool.execute(
            'SELECT id, title, author, cover_image, isbn FROM books ORDER BY created_at DESC LIMIT 3'
        );
        
        res.json({ code: 0, msg: '成功', data: books });
    } catch (error) {
        console.error('获取最新上架图书失败:', error);
        res.status(500).json({ msg: '服务器错误' });
    }
});

module.exports = router;